import { ecs } from "db://app-game/libs/ecs/ECS";
import { ECSEntity } from "db://app-game/libs/ecs/ECSEntity";
import { AgentModelComp } from "../model/AgentModelComp";

/**
 * @zh rov模拟器系统
 */
@ecs.register("Simulator")
export class SimulatorSystem
  extends ecs.ComblockSystem
  implements ecs.IEntityEnterSystem, ecs.ISystemUpdate
{
  filter(): ecs.IMatcher {
    return ecs.allOf(AgentModelComp);
  }
  entityEnter(entity: ECSEntity): void {
    const agentModel = entity.get(AgentModelComp);
    const id = agentModel.simulator.addAgent(null);
    const pos = agentModel.node.position;
    agentModel.simulator.setAgentPosition(id, pos.x, pos.y);
    agentModel.id = id;
    agentModel.simulator.setAgentGoal(id, 0, 0);
  }
  update(entity: ECSEntity, dt: number): void {
    // 移动回调
    const agentModel = entity.get(AgentModelComp);
    const pos = agentModel.simulator.getAgentPosition(agentModel.id);
    agentModel.moveCallback(pos);
  }
}
